package com.netease.dragonwar.sprite;

import com.netease.dragonwar.util.ImageUtils;

import java.awt.image.BufferedImage;

/**
 * @author louxj424
 * @version 0.1.0
 * @date 创建时间：2018年3月6日 下午7:22:13
 * @since jdk 1.7.0
 */
public class Enemy extends Sprite {

	/**
	 * 定义敌人移动的目标的坐标点的位置
	 */
	private int targetX;
	private int targetY;

	/**
	 * 敌人的图片
	 */
	private BufferedImage img = ImageUtils.getEnemyImage();

	public Enemy(int x, int y, int width, int height, int speed) {
		super(x, y, width, height, speed);
	}

	public int getTargetX() {
		return targetX;
	}

	public void setTargetX(int targetX) {
		this.targetX = targetX;
	}

	public int getTargetY() {
		return targetY;
	}

	public void setTargetY(int targetY) {
		this.targetY = targetY;
	}

	@Override
	public void move() {
		int distanceX = targetX - getX();
		int distanceY = targetY - getY();
		double distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
		int stepX = (int) (getSpeed() * distanceX / distance);
		int stepY = (int) (getSpeed() * distanceY / distance);
		setX(getX() + stepX);
		setY(getY() + stepY);
	}

	@Override
	public BufferedImage getImage() {
		return img;
	}

}
